import './assets/main.css'

import { createApp } from 'vue'
import { createI18n } from 'vue-i18n'
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import enUs from 'element-plus/es/locale/lang/en'
import idId from 'element-plus/es/locale/lang/id'

import App from './App.vue'
import router from './router'

import en from './locales/en'
import zh from './locales/zh'
import id from './locales/id'
import { getPreferredLanguage } from './utils/i18n'

// 获取默认语言
const preferredLanguage = getPreferredLanguage()

// Element Plus 语言映射
const elementLocales = {
  zh: zhCn,
  en: enUs,
  id: idId
}

const i18n = createI18n({
  legacy: false,
  locale: preferredLanguage,
  fallbackLocale: 'en',
  messages: {
    en,
    zh,
    id
  }
})

const app = createApp(App)

app.use(createPinia())
app.use(router)
app.use(i18n)
app.use(ElementPlus, {
  locale: elementLocales[preferredLanguage as keyof typeof elementLocales]
})

app.mount('#app')
